package tickets.tickets;

/**
 *
 * @author Hlib_Babii
 */
public class LimitedMoneyTicket extends LimitedTicket {
    
    private int ammount;
    
    private int travelPrice;

    LimitedMoneyTicket(Ticket baseTicket, int travelPrice, int ammount) {
        super(baseTicket);
        this.travelPrice = travelPrice;
        this.ammount = ammount;
    }    

    @Override
    PassageState check() {
        PassageState passageState;
        if (ammount > travelPrice) {
            return baseTicket.check();
        } else {   
            return PassageState.NO_MONEY_LEFT;
        }
    }
    
    @Override
    void putMoney(int ammount) {
        if (ammount < 0) {
            throw new IllegalArgumentException();
        }
        this.ammount += ammount;
    }   

    @Override
    void use() {
        assert ammount > travelPrice;
        
        ammount -= travelPrice;
        baseTicket.use();
    }
}
